Parse half-open ranges like -2 or 3-, and be a bit more liberal about
authorMatthias Clasen <mclasen@redhat.com>
Tue, 24 Apr 2007 20:16:35 +0000 (20:16 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 24 Apr 2007 20:16:35 +0000 (20:16 +0000)
2007-04-24  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtkprintunixdialog.c (dialog_get_page_ranges): Parse
        half-open ranges like -2 or 3-, and be a bit more liberal
        about whitespace.
        (dialog_set_page_ranges): Support half-open ranges.

        * gtk/gtkprintoperation.c (print_pages_idle): Substitute the
        number of pages in half-open ranges.
        (preview_iface_is_selected): Support half-open ranges here, too.

svn path=/trunk/; revision=17627

ChangeLog
gtk/gtkprintoperation.c
gtk/gtkprintunixdialog.c

index 6fe22887626faff1cdb0fcb1a314f86fc7577f6b..d0ba2bc18966c24490642b2a34b874d03d02ba31 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-04-24  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtkprintunixdialog.c (dialog_get_page_ranges): Parse
+       half-open ranges like -2 or 3-, and be a bit more liberal
+       about whitespace.
+       (dialog_set_page_ranges): Support half-open ranges.
+
+       * gtk/gtkprintoperation.c (print_pages_idle): Substitute the
+       number of pages in half-open ranges.
+       (preview_iface_is_selected): Support half-open ranges here, too.
+
 2007-04-24  Chris Wilson  <chris@chris-wilson.co.uk>
 
        * gtk/gtkicontheme.c (scan_directory): Ensure the 
index 2440a1dd716e05570cd97aaf5c5c06512b17c7a7..e1189d762fa635877a3cc849dba042f8a586b9a1 100644 (file)
@@ -214,7 +214,7 @@ preview_iface_is_selected (GtkPrintOperationPreview *preview,
       for (i = 0; i < priv->num_page_ranges; i++)
        {
          if (page_nr >= priv->page_ranges[i].start &&
-             page_nr <= priv->page_ranges[i].end)
+             (page_nr <= priv->page_ranges[i].end || page_ranges[i].end == -1)
            return TRUE;
        }
       return FALSE;
@@ -2018,6 +2018,7 @@ print_pages_idle (gpointer user_data)
   GtkPrintOperationPrivate *priv; 
   GtkPageSetup *page_setup;
   gboolean done = FALSE;
+  gint i;
 
   data = (PrintPagesData*)user_data;
   priv = data->op->priv;
@@ -2067,6 +2068,9 @@ print_pages_idle (gpointer user_data)
        {
          data->ranges = priv->page_ranges;
          data->num_ranges = priv->num_page_ranges;
+          for (i = 0; i < data->num_ranges; i++)
+            if (data->ranges[i].end == -1)
+              data->ranges[i].end = priv->nr_of_pages - 1;
        }
       else if (priv->print_pages == GTK_PRINT_PAGES_CURRENT &&
               priv->current_page != -1)
index 47d6c22e7aa188226544cd30ef9fa899f2a43072..e72d7c4b969e984300fcff6705c3359575753af0 100644 (file)
@@ -1652,22 +1652,33 @@ dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
   p = text;
   while (*p)
     {
-      start = (int)strtol (p, &next, 10);
-      if (start < 1)
-       start = 1;
+      while (isspace (*p)) p++;
+
+      if (*p == '-')
+        {
+          /* a half-open range like -2 */
+          start = 1;
+        }
+      else
+        {
+          start = (int)strtol (p, &next, 10);
+          if (start < 1)
+           start = 1;
+          p = next;
+        }
+      
       end = start;
 
-      if (next != p)
-       {
-         p = next;
+      while (isspace (*p)) p++;
 
-         if (*p == '-')
-           {
-             p++;
-             end = (int)strtol (p, NULL, 10);
-             if (end < start)
-               end = start;
-           }
+      if (*p == '-')
+       {
+         p++;
+         end = (int)strtol (p, &next, 10);
+          if (next == p) /* a half-open range like 2- */
+            end = 0;
+         else if (end < start)
+           end = start;
        }
 
       ranges[i].start = start - 1;
@@ -1685,6 +1696,9 @@ dialog_get_page_ranges (GtkPrintUnixDialog *dialog,
 
   *n_ranges_out = i;
   
+  for (i = 0; i < *n_ranges_out; i++)
+    g_print ("[%d, %d]\n", ranges[i].start, ranges[i].end);
+
   return ranges;
 }
 
@@ -1702,6 +1716,8 @@ dialog_set_page_ranges (GtkPrintUnixDialog *dialog,
       g_string_append_printf (s, "%d", ranges[i].start + 1);
       if (ranges[i].end > ranges[i].start)
        g_string_append_printf (s, "-%d", ranges[i].end + 1);
+      else if (ranges[i].end == -1)
+        g_string_append (s, "-");
       
       if (i != n_ranges - 1)
        g_string_append (s, ",");